package action;

import java.util.List;

import domain.TPrivilege;

public class TreeGenerateUtil
{

	/**
	 * @param args
	 */
	
 public static StringBuffer treeBuildRoot(List<TPrivilege> nodeLists,TPrivilege rootNode )
 {
   StringBuffer tree =new StringBuffer(); 
   tree.append("<ul id='rootNode' class='treeview'>");
   tree.append("<li><img src='script/menu/open.gif' id='"+rootNode.getId()+"_mark'/><a href='javascript:expconFolder("+rootNode.getId()+")' ><img src='script/menu/folderOpen.gif' id='"+rootNode.getId()+"_folder' />"+rootNode.getName()+"</a>");
   tree.append("<ul id='"+rootNode.getId()+"_ulnode'>");
   for(TPrivilege privilege:nodeLists)
   {
     if(privilege.getIsLeaf() == 1)
		   tree.append(buildLeaf(privilege));
	   else 
	   {
	     tree.append(buildNode(privilege));
	     tree.append("<input id='"+privilege.getId()+"_needload' type='hidden' value='0'>");
	   }
	    
   }
   tree.append("</ul>");
   tree.append("</li>");
   tree.append("</ul>");
   return tree;
 }
 
 public static StringBuffer buildNodes(List<TPrivilege> nodeLists)
 {
	   
	 StringBuffer tree =new StringBuffer(); 
	  for(TPrivilege privilege:nodeLists)
	   {
		   if(privilege.getIsLeaf() == 1)
			   tree.append(buildLeaf(privilege));
		   else 
		   {
		     tree.append(buildNode(privilege));
		     tree.append("<input id='"+privilege.getId()+"_needload' type='hidden' value='0'>");
		   }
			   
	   }
	   return tree;
 }
	
	public static String buildNode(TPrivilege  node)
	{
		String tree = "<li><a href='javascript:expconFolder("+node.getId()+")' ><img src='script/menu/close.gif' id='"+node.getId()+"_mark'/></a><img src='script/menu/folderClosed.gif' id='"+node.getId()+"_folder' />"+node.getName();		
		tree = tree+"<ul id='"+node.getId()+"_ulnode' style='display:none'>";
		tree = tree+"</ul>";
		tree = tree+"</li>";
		return tree;
	}
	
	
	public static String buildLeaf(TPrivilege  node)
	{
		String tree = "<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a><img src='script/menu/iconText.gif' id='"+node.getId()+"_folder' />"+node.getName()+"</a></li>";		
	   return tree;
	}
	
	public static void main(String[] args)
	{

	}

}
